home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / misc / avmNfax1_33.lha / AVMSuite / rexx / handledata.avm < prev    next >
Text File  |  1994-06-24  |  12KB  |  480 lines

  1. /* TITLE: avm:rexx/handledata.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername mailbox .
  23. if symbol('mailbox') ~= 'VAR' | mailbox = '' then mailbox = 'manual'
  24.  
  25. 'turnoffvoicemode'
  26.  
  27. 'assumemode' 'Unknown'
  28.  
  29. 'setserial' '19200' '8' 'N' '1' '7Wire'
  30. action = rc
  31. select
  32.   when action = 0 then nop
  33.   when action = 14 then signal stderror
  34.   when action = 16 then signal stderror
  35.   otherwise signal arexxerror
  36. end
  37.  
  38. 'writeline' 'ATA'
  39. 'readline' '90'
  40. action = rc
  41. select
  42.   when action = 0 then nop
  43.   when action = 10 then signal answerdataabort
  44.   when action = 12 then signal answerdataabort
  45.   when action = 14 then signal stderror
  46.   when action = 16 then signal stderror
  47.   otherwise signal arexxerror
  48. end
  49.  
  50. 'readline' '90'
  51. action = rc
  52. if action = 0 then value = result
  53. select
  54.   when action = 0 then nop
  55.   when action = 10 then signal answerdataabort
  56.   when action = 12 then signal answerdataabort
  57.   when action = 14 then signal stderror
  58.   when action = 16 then signal stderror
  59.   otherwise signal arexxerror
  60. end
  61.  
  62. if (left(value, 7) = 'CONNECT') then do
  63.   call showDebugger('Connected in DATA mode.'); call time('r')
  64.   address rexx 'startbbs' value
  65.   call showLog('BBS done.', 1, trunc(time('e')))
  66. end; else do
  67.   call showDebugger('Failed to connect in DATA mode.')
  68.   call showLog('BBS attempted.', 0, 0)
  69. end
  70.  
  71. finished:
  72. do 5
  73.  
  74. 'readline' '2'
  75. action = rc
  76. if action = 0 then value = result
  77. select
  78.   when action = 0 then nop
  79.   when action = 10 then signal answerabortreadall
  80.   when action = 12 then signal stdabort
  81.   when action = 14 then signal stderror
  82.   when action = 16 then signal stderror
  83.   otherwise signal arexxerror
  84. end
  85.  
  86. end
  87.  
  88. answerabortreadall:
  89. exit
  90.  
  91. answerdataabort:
  92. 'writeline' 'A'
  93. signal finished
  94.  
  95. showLog:
  96. procedure expose mailbox
  97. parse arg mycomment, gotData, actualLength
  98. handle = makeUniqueFile()
  99. call initLogEntry()
  100. log.comment = mycomment; log.length = actualLength
  101. if gotData = 1 then log.type = 'BBS'; else log.type = 'Try_BBS'
  102. call saveLogEntry(mailbox, handle)
  103. return
  104.  
  105. /* TITLE: avm:rexx/simplestdtail.avm */
  106. /* This is the standard tail */
  107. exit
  108.  
  109. exit
  110.  
  111. mailboxDir: procedure
  112.     parse arg mailbox
  113.  
  114.     return 'avm:' || mailbox || '/'
  115.  
  116. logFile: procedure
  117.     parse arg mailbox, magiccookie
  118.  
  119.     return 'avm:' || mailbox || '/logs/' || magiccookie
  120.  
  121. voiceFile: procedure
  122.     parse arg mailbox, magiccookie
  123.  
  124.         if (verify(magiccookie, '/:', 'M') = 0) then
  125.           return 'avm:' || mailbox || '/voices/' || magiccookie
  126.         else
  127.           return magiccookie
  128.  
  129. makeUniqueFile: procedure
  130.     if arg() ~= 0 then do
  131.         rc = "makeUniqueFile: bad args"
  132.         signal error
  133.     end
  134.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  135.  
  136. convertToDate: procedure
  137.     if arg() ~= 1 then do
  138.         rc = "convertToDate: bad args"
  139.         signal error
  140.     end
  141.     parse arg timeInC
  142.  
  143.     actualTime = (timeInC - (2922)*86400) // (86400)
  144.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  145.  
  146.     return actualDate /* returning it in 'internal' format */
  147.  
  148. convertToTime: procedure
  149.     if arg() ~= 1 then do
  150.         rc = "convertToTime: bad args"
  151.         signal error
  152.     end
  153.     parse arg timeInC
  154.     
  155.     actualTime = (timeInC - (2922)*86400) // (86400)
  156.  
  157.     return actualTime
  158.  
  159. cTime: procedure
  160.     /* 2922 = 8*365 + 2 */
  161.     /* 86400 = 24*60*60 */
  162.     return (date('i')+2922)*86400 + time('s')
  163.  
  164. /* this returns a handle that you must use after initializing log. */
  165. initLogEntry: procedure expose log.
  166.     if arg() ~= 0 then do
  167.         rc = "initLogEntry: bad args"
  168.         signal error
  169.     end
  170.     
  171.     drop log.
  172.         log. = ''
  173.  
  174.         acidname = getclip(address() || 'CIDNAME')
  175.         acidnumber = getclip(address() || 'CIDNUMBER')
  176.  
  177.     /* 2922 = 8*365 + 2 */
  178.     /* 86400 = 24*60*60 */
  179.     log.time = (date('i')+2922)*86400 + time('s')
  180.     log.cidname = acidname
  181.     log.cidnumber = acidnumber
  182.  
  183.     return
  184.  
  185. loadLogEntry: procedure expose log.
  186.     if arg() ~= 2 then do
  187.         rc = "loadLogEntry: bad args"
  188.         signal error
  189.     end
  190.     parse arg mailbox, handle
  191.  
  192.         drop log.
  193.         log. = ''
  194.  
  195.     if ~exists(mailboxDir(mailbox)) then do
  196.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  197.         return
  198.     end
  199.  
  200.     opened = open(handle, logFile(mailbox, handle), 'r')
  201.         if opened then do
  202.         call showDebugger('Loading entry' logFile(mailbox, handle))
  203.         do while ~eof(handle)
  204.             line = readln(handle)
  205.             parse upper var line variable '=' value
  206.             log.variable = value
  207.         end
  208.         call close(handle)
  209.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  210.     return
  211.  
  212. /* pass a handle here */
  213. saveLogEntry: procedure expose log.
  214.     if arg() ~= 2 then do
  215.         rc = "saveLogEntry: bad args"
  216.         signal error
  217.     end
  218.     parse arg mailbox, handle
  219.  
  220.     if ~exists(mailboxDir(mailbox)) then do
  221.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  222.         return
  223.     end
  224.  
  225.     opened = open(handle, logFile(mailbox, handle), 'w')
  226.  
  227.     if opened then do
  228.         call showDebugger('Saving entry' logFile(mailbox, handle))
  229.         call writeln(handle, 'TYPE=' || log.type)
  230.         call writeln(handle, 'TIME=' || log.time)
  231.         call writeln(handle, 'LENGTH=' || log.length)
  232.  
  233.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  234.  
  235.         call writeln(handle, 'CIDNAME=' || log.cidname)
  236.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  237.  
  238.         call writeln(handle, 'COMMENT=' || log.comment)
  239.  
  240.         call writeln(handle, 'FILENAME=' || log.filename)
  241.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  242.  
  243.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  244.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  245.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  246.  
  247.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  248.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  249.  
  250.         call close(handle)
  251.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  252.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  253.  
  254.     return
  255.  
  256. /* pass a handle here */
  257. updateLogEntry: procedure expose log.
  258.     if arg() ~= 2 then do
  259.         rc = "updateLogEntry: bad args"
  260.         signal error
  261.     end
  262.     parse arg mailbox, handle
  263.  
  264.     if ~exists(mailboxDir(mailbox)) then do
  265.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  266.         return
  267.     end
  268.  
  269.     if ~exists(logFile(mailbox, handle)) then do
  270.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  271.         return
  272.     end
  273.     opened = open(handle, logFile(mailbox, handle), 'w')
  274.  
  275.     if opened then do
  276.         call showDebugger('Updating entry' logFile(mailbox, handle))
  277.         call writeln(handle, 'TYPE=' || log.type)
  278.         call writeln(handle, 'TIME=' || log.time)
  279.         call writeln(handle, 'LENGTH=' || log.length)
  280.  
  281.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  282.  
  283.         call writeln(handle, 'CIDNAME=' || log.cidname)
  284.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  285.  
  286.         call writeln(handle, 'COMMENT=' || log.comment)
  287.  
  288.         call writeln(handle, 'FILENAME=' || log.filename)
  289.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  290.  
  291.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  292.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  293.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  294.  
  295.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  296.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  297.  
  298.         call close(handle)
  299.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  300.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  301.  
  302.     return
  303.  
  304.  
  305.  
  306. showDebugger: procedure
  307.     if arg() ~= 1 then do
  308.         say "showDebugger: ERROR"
  309.         exit 20
  310.     end
  311.  
  312.     parse arg debuggerInfo
  313.     
  314.     firstLine = sourceline(1)
  315.     parse var firstLine '/*' 'TITLE:' title '*/'
  316.     if showlist('p', 'AVMLOGGER') then
  317.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  318.     else
  319.         say title ':' debuggerInfo
  320.  
  321.     return 
  322.  
  323. /*-----------------------------------------------------------------------*/
  324. /*                         signal processing                             */
  325.  
  326. arexxerror:
  327. error:
  328.     call showDebugger("Error" rc "at line" sigl)
  329.     exit 20
  330.  
  331. break_c:
  332. halt:
  333.     call showDebugger("Halt/Break_C at line" sigl)
  334.     exit 20
  335.  
  336. novalue:
  337.     call showDebugger("No value at line" sigl)
  338.     exit 20
  339.  
  340. syntax:
  341.     call showDebugger("Syntax error" rc "at line" sigl)
  342.     exit 20
  343.  
  344. exit
  345.  
  346. /* this requires logfunctions.avm */
  347.  
  348. loadMailbox: procedure expose mailbox.
  349.     if arg() ~= 1 then do
  350.         rc = "loadMailbox: bad args"
  351.         signal error
  352.     end
  353.  
  354.         mailbox. = ''
  355.     parse arg mailbox
  356.  
  357.     handle = 'mailboxconfig'
  358.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
  359.     if opened then do
  360.         do while ~eof(handle)
  361.             line = readln(handle)
  362.             parse upper var line variable '=' value
  363.             mailbox.variable = value
  364.         end
  365.         call close(handle)
  366.     end
  367.     return
  368.  
  369. /* pass a handle here */
  370. saveMailbox: procedure expose mailbox.
  371.     if arg() ~= 1 then do
  372.         rc = "saveMailbox: bad args"
  373.         signal error
  374.     end
  375.     parse arg mailbox
  376.  
  377.     handle = 'mailboxconfig'
  378.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
  379.  
  380.     if opened then do
  381.         call writeln(handle, 'PASSWORD=' || mailbox.password)
  382.  
  383.         call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
  384.         call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
  385.         call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
  386.  
  387.         call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
  388.         call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
  389.         call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
  390.         call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
  391.  
  392.         call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
  393.         call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
  394.         call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
  395.         call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
  396.  
  397.         call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
  398.         call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
  399.         call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
  400.  
  401.         call close(handle)
  402.     end
  403.  
  404.     return
  405.  
  406. stdabort:
  407. exit
  408.  
  409. stdbusy:
  410. exit
  411.  
  412. stderror:
  413. exit
  414.  
  415. stdtimedout:
  416. exit
  417.  
  418. stdfaxinstruct:
  419. 'playvoice' 'avm:voices/FaxStarting'
  420. action = rc
  421. select
  422.   when action = 0 then nop
  423.   when action = 1 then do; call checkifabort; end
  424.   when action = 4 then nop
  425.   when action = 5 then nop
  426.   when action = 8 then signal stdbusy
  427.   when action = 12 then signal stdabort
  428.   when action = 14 then nop
  429.   when action = 16 then nop
  430.   otherwise signal arexxerror
  431. end
  432.  
  433. stdfax:
  434. faxscript = getclip(address() || 'FAXSCRIPT')
  435. if faxscript = '' then faxscript = 'handlefax'
  436. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  437. else address rexx faxscript address() 'anonymous'
  438. exit
  439.  
  440. stddatainstruct:
  441. 'playvoice' 'avm:voices/DataStarting'
  442. action = rc
  443. select
  444.   when action = 0 then nop
  445.   when action = 1 then do; call checkifabort; end
  446.   when action = 4 then nop
  447.   when action = 5 then nop
  448.   when action = 8 then signal stdbusy
  449.   when action = 12 then signal stdabort
  450.   when action = 14 then nop
  451.   when action = 16 then nop
  452.   otherwise signal arexxerror
  453. end
  454.  
  455. stddata:
  456. datascript = getclip(address() || 'DATASCRIPT')
  457. if datascript = '' then datascript = 'handledata'
  458. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  459. else address rexx datascript address()
  460. exit
  461.  
  462. checkifabort:
  463. 'readnkeys' '1' '3'
  464. action = rc
  465. if action = 0 then value = result
  466. select
  467.   when action = 0 then do; if value = '*' then signal stdabort; end
  468.   when action = 4 then nop
  469.   when action = 5 then nop
  470.   when action = 8 then signal stdbusy
  471.   when action = 10 then nop
  472.   when action = 12 then signal stdabort
  473.   when action = 14 then signal stderror
  474.   when action = 16 then signal stderror
  475.   otherwise signal arexxerror
  476. end
  477. return
  478.  
  479.  
  480.